package com.java.example.app

import android.app.Application
import android.content.Context
import androidx.multidex.MultiDex
import cn.jiguang.api.utils.JCollectionAuth
import cn.jpush.android.api.JPushInterface
import com.blankj.utilcode.util.SPUtils
import com.blankj.utilcode.util.Utils
import com.clj.fastble.BleManager
import com.tencent.bugly.crashreport.CrashReport
import com.java.example.util.LogUtil
import com.java.example.util.SpeakUtils
import com.java.example.util.crash.CrashHandler
import okhttp3.logging.HttpLoggingInterceptor

class MyApplication : Application() {

    override fun onCreate() {
        super.onCreate()
        sInstance = this
        //极光推送
//        JCollectionAuth.setAuth(mContext, false);
        val isFirst = SPUtils.getInstance().getBoolean(Constant.IS_FIRST_SHOW_AGREE, true)
        if (!isFirst) {
            initSDK()
        }
    }

    override fun attachBaseContext(base: Context?) {
        super.attachBaseContext(base)
        MultiDex.install(this)
    }

    fun initSDK() {
        SpeakUtils.init(this)

        CrashReport.initCrashReport(applicationContext, "19898c2bb1", false)
        //本地异常处理
        val crashHandler: CrashHandler = CrashHandler.getInstance()
        crashHandler.init(applicationContext)


        //网络请求的log
        val loggingInterceptor = HttpLoggingInterceptor { s -> LogUtil.printJson("OkHttp", s, "") }
        loggingInterceptor.level = HttpLoggingInterceptor.Level.BODY

        Latte.init(this)
            .withInterceptor(loggingInterceptor)
            .configure()
        BleManager.getInstance().init(this)
        Utils.init(this)
        //极光推送
        JCollectionAuth.setAuth(this, true)
        JPushInterface.setDebugMode(true)
        JPushInterface.init(this)

    }

    companion object {
        lateinit var sInstance: MyApplication
    }
}